package com.kelp.codetoolkit.utils

import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.kelp.codetoolkit.utils.frame.SpringUtil

/**
 * @author: liuyuebai
 * @date: 2024/9/10 18:09
 * @description:
 */
object PathUtil {

    /**
     * 获取当前项目基本路径
     */
    fun getProjectPath(project: Project): String {
        return project.guessProjectDir()?.path ?: ""
    }

    fun getApplicationPath(module: Module): String {
        return SpringUtil.getSpringBootApplicationPath( module)
    }

    fun getResourcePath(module: Module): String {
        val projectDir = module.project.guessProjectDir()
        return ""
    }

    fun replaceInPath(path: String, originalStr:String,replacement: String): String {
        val parts = path.split("/")
        return parts.map { part ->
            if (part.contains(originalStr)  &&!part.contains("-$originalStr")) {
                part.replace(originalStr, replacement)
            } else {
                part
            }
        }.joinToString("/")
    }

    fun replaceServiceImplPath(path: String, originalStr:String,replacement: String): String {
        val parts = path.split("/")
        return parts.map { part ->
            if (part.contains(originalStr)  &&!part.contains("-$originalStr")) {
                part.replace(originalStr, replacement)
            } else {
                part
            }
        }.joinToString("/")
    }
}